import pandas as pd

df = pd.read_csv('region_t.csv')

p_id = set()
c_id = set()
d_id = set()
p = []
c = []
d = []
for index, row in df.iterrows():
    ## "province_name","province_area_code","city_name","city_area_code","district_name","district_area_code"
    province_name = row['province_name']
    province_area_code = row['province_area_code']
    city_name = row['city_name']
    city_area_code = row['city_area_code']
    district_name = row['district_name']
    district_area_code = row['district_area_code']

    provice = {
        "label": province_name,
        "value": "{:.0f}".format(province_area_code)
    }
    city = {
        "label": city_name,
        "value": "{:.0f}".format(city_area_code)
    }
    district = {
        "label": district_name,
        "value": "{:.0f}".format(district_area_code)
    }

    if province_area_code not in p_id:
        p_id.add(province_area_code)
        p.append(provice)
        c.append([])
        d.append([])
    
    if city_area_code not in c_id:
        c_id.add(city_area_code)
        c[p.index(provice)].append(city)
        d[p.index(provice)].append([])
    
    d[p.index(provice)][c[p.index(provice)].index(city)].append(district)

with open('province.js', 'w', encoding="utf-8") as f:
    f.write('var provinceData = ' + str(p) + '\nexport default provinceData;')

with open('city.js', 'w', encoding="utf-8") as f:
    f.write('var cityData = ' + str(c) + '\nexport default cityData;')

with open('area.js', 'w', encoding="utf-8") as f:
    f.write('var areaData = ' + str(d) + '\nexport default areaData;')